package xiyuan.view.data;

import java.util.Collections;
import java.util.List;

import xiyuan.data.DatabaseUtil;
import xiyuan.keywords.tfidf.KeyWord;

public class WeiboUser {
	private long uid;
	private String username;
	private String[] keywords;
	private double[] distance;
	public WeiboUser clone(){
		WeiboUser user = new WeiboUser();
		user.setUid(getUid());
		user.setUsername(getUsername());
		user.setDistance(this.getDistance().clone());
		user.setKeywords(this.getKeywords().clone());
		return user;
	}
	public WeiboUser(long uid, int distanceLength, int keywordLength, boolean getKeyword) {
		this.uid = uid;
		this.distance = new double[distanceLength];
		List<KeyWord> keywordsList;
		if (getKeyword && DatabaseUtil.userExist(uid)) {
			keywordsList = DatabaseUtil.getKeywordByUID(uid);
			if (keywordsList.size()<keywordLength)
				keywordLength = keywordsList.size();
			this.keywords = new String[keywordLength];
			Collections.sort(keywordsList);
			for (int i = 0; i<keywordLength;i++){
				keywords[i] = keywordsList.get(i).getWord();
			}
		}
	}
	public WeiboUser(){
		
	}
	/**
	 * @param uid the uid to set
	 */
	public void setUid(long uid) {
		this.uid = uid;
	}
	/**
	 * @return the uid
	 */
	public long getUid() {
		return uid;
	}
	/**
	 * @param username the username to set
	 */
	public void setUsername(String username) {
		this.username = username;
	}
	/**
	 * @return the username
	 */
	public String getUsername() {
		return username;
	}
	/**
	 * @param keywords the keywords to set
	 */
	public void setKeywords(String[] keywords) {
		this.keywords = keywords;
	}
	/**
	 * @return the keywords
	 */
	public String[] getKeywords() {
		return keywords;
	}
	/**
	 * @param doubles the distance to set
	 */
	public void setDistance(Double[] doubles) {
		double[] tmp = new double[doubles.length];
		for (int i = 0; i < doubles.length; i++){
			tmp[i] = doubles[i];
		}
		this.distance = tmp;
	}
	public void setDistance(double[] doubles){
		this.distance = doubles;
	}
	/**
	 * @return the distance
	 */
	public double[] getDistance() {
		return distance;
	}
}
